$(function () {
    var getParams = getArgs();
    var currentHotel = getParams.hotel;
    var vipInfoId = getParams.no;
    var vipUserId = getParams.user;
    var color = getParams.cl;
    toastr.options = {
        "newestOnTop": false,
        "timeOut": 1500,
        "extendedTimeOut": 0,
        "escapeHtml": true,
        "positionClass": "toast-bottom-center"
    };
    if (currentHotel === undefined || currentHotel === '') {
        toastr.error(lang('toastr.grogshop'));
        return;
    }     
    var isWechatBrowser = function() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    };    
    var colorArray = ['background-green','background-yellow','background-blue','background-purple','background-red'];
    var docBody = $('#doc-body');
    var cardDetail = $('#card-info');
    var originalHref = cardDetail.find('.go-reservation').attr('href');
    cardDetail.find('.go-reservation').attr('href', originalHref + '?hotel=' + currentHotel + '&name=Bind');
    cardDetail.find('.info-head-content').addClass(colorArray[color]);
    var recordoriginalHref = cardDetail.find('.go-cardrecord').attr('href');
    var explainoriginalHref = cardDetail.find('.go-cardexplain').attr('href');
    var requestCard = function () {
        toggleLoading(true);
        ajaxRequest('/Home/Customer/hasUserVipCardDetial', {
            "hotel": currentHotel,
            "vipInfoId": vipInfoId,
            "vipUserId": vipUserId
        }, 'post', function (data) {
            toggleLoading(false);
            var info = data.data;
            if(info.length !== 0){
                cardDetail.find('.card-hotel-name').text(info.couponName);
                cardDetail.find('.typo-text-mobile').text(info.mobile);
                cardDetail.find('.grade').text(info.vipname);
                cardDetail.find('.price span').text(info.receipt);
                cardDetail.find('.card-hotel-price span').text(info.cardPrice);
                cardDetail.find('.card-hotel-price span').text(info.cardPrice);
                cardDetail.find('.times').text(info.checkin);
                cardDetail.find('.card-hotel-name').text(info.hotelName);
                cardDetail.find('.hotel-name').text(info.hotelName);
                cardDetail.find('.card-hotel-image').attr('data-original', info.logo);
                cardDetail.find('.go-cardrecord').attr('href', recordoriginalHref + '?hotel=' + currentHotel + '&no='+info.vipUserId);
                cardDetail.find('.go-cardexplain').attr('href', explainoriginalHref + '?hotel=' + currentHotel + '&no='+info.vipInfoId+ "&user=" + info.vipUserId);
                if(info.ali == 1){
                    $('.recharge-btn').removeClass('hidden');
                }
                if(info.wechat == 1 && isWechatBrowser()){
                    $('.recharge-btn').removeClass('hidden');
                }
                if(info.isCharge){
                    $('.recharge-btn').removeClass('hidden');
                }else{
                    $('.recharge-btn').addClass('hidden');
                }
                cardDetail.on('click','.recharge-btn',function(e){
                    e.stopPropagation();
                    window.location.href = "/Home/PayPage/recharge?hotel=" + currentHotel + "&no=" + info.vipUserId + "&cl="+color + "&info="+vipInfoId;
                }); 
                docBody.removeClass('hidden');
                $('#doc .card-hotel-image').lazyload({
                    'skip_invisible': true
                }); 
            }else{
                toastr.error(lang('member.14'));
                docBody.addClass('hidden');
            }
        }, function(error){
            toggleLoading(false); 
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });        
    }
    requestCard();  
});
